package cn.yousuowei.huanglele.scanmine;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class ResultActivity extends AppCompatActivity {

    private TextView result_head_text;
    private ImageView result_img;
    private TextView result_used_time;
    private Button result_again_btn;
    private Button result_index_btn;
    private ResultActivity mContext;
    private int level = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        setTitle("");
        mContext = this;

        result_head_text = (TextView) findViewById(R.id.result_head_text);
        result_img = (ImageView) findViewById(R.id.result_img);
        result_used_time = (TextView) findViewById(R.id.result_used_time);
        result_again_btn = (Button) findViewById(R.id.result_again_btn);
        result_index_btn = (Button) findViewById(R.id.result_index_btn);

        Intent intent = getIntent();
        Boolean is_win = intent.getBooleanExtra("is_win",false);
        String used_time = intent.getStringExtra("used_time");
        level = intent.getIntExtra("level",0);
        String head = "挑战失败";
        int img = R.drawable.fail;
        if(is_win){
            head = "挑战成功";
            img = R.drawable.success;
        }
        result_head_text.setText(head);
        result_used_time.setText(used_time);
        result_img.setImageResource(img);
        result_again_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_r = new Intent(mContext,MineActivity.class);
                intent_r.putExtra("level",mContext.level);
                startActivity(intent_r);
                finish();
            }
        });
        result_index_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_r = new Intent(mContext,MainActivity.class);
                startActivity(intent_r);
                finish();
            }
        });
    }


    /**
     * 点击返回退出到桌面
     */
    @Override
    public void onBackPressed() {
        Intent intent_r = new Intent(mContext,MineActivity.class);
        intent_r.putExtra("level",this.level);
        startActivity(intent_r);
        finish();
    }
}
